package demo1enum;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xiaotutu
 * Date: 2025-01-15
 * Time: 20:59
 */
public enum TestEnum {
    RED(0.1,"红色"),BLACK(1.1,"黑色"),
    GREEN(2.1,"绿色"),WHITE(3.1,"白色");

    public String color;
    public double ordinal;

    private TestEnum(double ordinal, String color) {
        this.color = color;
        this.ordinal = ordinal;

    }

    @Override
    public String toString() {
        return "TestEnum{" +
                "color='" + color + '\'' +
                ", ordinal=" + ordinal +
                '}';
    }

    public static void main(String[] args) {
        TestEnum[] testEnum2 = TestEnum.values();

        for (int i = 0; i < testEnum2.length; i++) {
            System.out.println(testEnum2[i] + " ");
        }

        TestEnum testEnum1 = TestEnum.valueOf("RED");
        System.out.println(testEnum1);

        System.out.println(BLACK.compareTo(GREEN));

    }

    public static void main1(String[] args) {
        TestEnum testEnum = TestEnum.BLACK;
        switch (testEnum) {
            case RED:
                System.out.println("RED");
                break;
            case BLACK:
                System.out.println("BLACK");
                break;
            case GREEN:
                System.out.println("GREEN");
                break;
            default:
                System.out.println("颜色错误");
                break;
        }
    }
}
